﻿using System;
using System.Windows.Forms;
using BasecampRestAPI;

namespace BasecampUI
{
	public class CredentialsMainFormMediator
	{
		private readonly ICredentialsMainForm _form;

		public static CredentialsMainFormMediator GetInstance(ICredentialsMainForm form)
		{
			return new CredentialsMainFormMediator(form);
		}
		private CredentialsMainFormMediator(ICredentialsMainForm form)
		{
			_form = form;
		}

		public bool GetBaseCampFromCredentials(out IBaseCamp camp)
		{
			using (ICredentialsForm credentials = _form.CredentialsForm)
			{
				if (DialogResult.OK != credentials.ShowDialog())
				{
					_form.Close();
					camp = null;
					return false;
				}
				camp = _form.GetBaseCamp(credentials.Service);
			}
			return true;
		}
	}
}
